package gui;

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import utils.SynapseRandomizer;
import utils.math_utils.RandStream;
import utils.math_utils.RandStream.Rand;

public class UDFPanel extends JPanel {

	private RandomizerPanel U;
	private RandomizerPanel D;
	private RandomizerPanel F;
	private boolean targEx;
	private boolean srcEx;
	private FlowLayout layout;
	
	private SynapseRandomizer synR;
	
	public UDFPanel(SynapseRandomizer synR, boolean srcEx, boolean targEx) {
		this.synR = synR;
		this.srcEx = srcEx;
		this.targEx = targEx;
		layout = new FlowLayout();
		layout.setAlignment(FlowLayout.LEADING);
		this.setLayout(layout);
		initializePanels();
		initializeLayout();
	}
	
	public void initializePanels () {
		
		if(targEx && srcEx) {
			U = new RandomizerPanel(new RandStream(Rand.GAUSS, 0.5, 0.25,
					0.001, Double.MAX_VALUE, true));
			D = new RandomizerPanel(new RandStream(Rand.GAUSS, 1100, 550,
					0.001, Double.MAX_VALUE, true));
			F = new RandomizerPanel(new RandStream(Rand.GAUSS, 50, 25,
					0.001, Double.MAX_VALUE, true));
		} else if(srcEx && !targEx) {
		
			U = new RandomizerPanel(new RandStream(Rand.GAUSS, 0.05, 0.025,
				0.001, Double.MAX_VALUE, true));
			D = new RandomizerPanel(new RandStream(Rand.GAUSS, 125, 62.5,
				0.001, Double.MAX_VALUE, true));
			F = new RandomizerPanel(new RandStream(Rand.GAUSS, 120, 60,
				0.001, Double.MAX_VALUE, true));
			
		} else if(!srcEx && targEx) {
			
			U = new RandomizerPanel(new RandStream(Rand.GAUSS, 0.25, 0.125,
				0.001, Double.MAX_VALUE, true));
			D = new RandomizerPanel(new RandStream(Rand.GAUSS, 700, 350,
				0.001, Double.MAX_VALUE, true));
			F = new RandomizerPanel(new RandStream(Rand.GAUSS, 20, 10,
				0.001, Double.MAX_VALUE, true));
		
		} else {
			U = new RandomizerPanel(new RandStream(Rand.GAUSS, 0.32, 0.16,
					0.0001, Double.MAX_VALUE, true));
			D = new RandomizerPanel(new RandStream(Rand.GAUSS, 144, 72,
					0.001, Double.MAX_VALUE, true));
			F = new RandomizerPanel(new RandStream(Rand.GAUSS, 60, 30,
					0.001, Double.MAX_VALUE, true));
		}
		
	}
	
	public void initializeLayout(){
		Border b = BorderFactory.createLineBorder(Color.gray);
		TitledBorder tb = BorderFactory.createTitledBorder(b, "U");
		
		U.setBorder(tb);
		
		tb = BorderFactory.createTitledBorder(b, "D");
		
		D.setBorder(tb);
		
		tb = BorderFactory.createTitledBorder(b, "F");
		
		F.setBorder(tb);
		
		this.add(U);
		this.add(D);
		this.add(F);
	}
	
	public SynapseRandomizer closeDialogOk() {
		synR.setU(U.closeDialogOk());
		synR.setD(D.closeDialogOk());
		synR.setD(F.closeDialogOk());
		return synR;
	}
	
	
	
}
